package com.school.fragment;



import java.util.ArrayList;
import java.util.List;

import com.school.activity.R;
import com.school.adapter.PerformanceExpandAdapter;
import com.school.domain.Grade;
import com.school.net.GetGreade;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

public class PerformanceFragment extends Fragment {
	private View mParent;
	private ExpandableListView expandableListView;
	private FragmentActivity mActivity;
	private List<Grade> grades=new ArrayList<Grade>();
	private PerformanceExpandAdapter adapter;
	/**
	 * Create a new instance of DetailsFragment, initialized to show the text at
	 * 'index'.
	 */
	public static TimetableFragment newInstance(int index) {
		TimetableFragment f = new TimetableFragment();

		// Supply index input as an argument.
		Bundle args = new Bundle();
		args.putInt("index", index);
		f.setArguments(args);

		return f;
	}

	public int getShownIndex() {
		return getArguments().getInt("index", 0);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		// TODO Auto-generated method stub	
		mActivity = getActivity();
		mParent = getView();
		adapter=new PerformanceExpandAdapter(mActivity, grades);
		expandableListView=(ExpandableListView) mParent.findViewById(R.id.performance_listview_list);
		expandableListView.setGroupIndicator(null);
		expandableListView.setAdapter(adapter);
		new MyAsyncTask().execute("");
		//mTitle = (TitleView) mParent.findViewById(R.id.title);
	}

	public class MyAsyncTask extends AsyncTask<String, String, String>{
		@Override
		protected String doInBackground(String... params) {
			grades=new GetGreade().getGrades();
			System.out.println("---------------------------------"+grades.size());
//			grades.remove(0);
			return null;
		}

		@Override
		protected void onPostExecute(String result) {
			adapter.setGrades(grades);
			adapter.notifyDataSetChanged();
		}
		
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_performance, container, false);
		new MyAsyncTask().execute("");
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
	}
	@Override
	public void onHiddenChanged(boolean hidden) {
		// TODO Auto-generated method stub
		super.onHiddenChanged(hidden);
	}

}
